package misc

import (
	"dhfshop/controllers/base"
	//"github.com/astaxie/beego"
	"github.com/astaxie/beego/validation"
	"wxsdk/miniapp/core"
)

type ImgProxyController struct {
	base.BaseController
}

func (this *ImgProxyController) ProxyGet() {
    v := struct {
	    Url       string  `form:"url" valid:"Required"`
	}{} 
	this.ParseForm(&v)
	valid := validation.Validation{}
	passed, _ := valid.Valid(&v)
	if !passed {
		this.ServeError(valid.Errors[0].Key+" "+valid.Errors[0].Message)
		return 
	}
	data, err := core.GetCommonFileByHttp(v.Url)
	if err != nil {
	    this.ServeError(err.Error())
		return
	}
	this.Ctx.ResponseWriter.Write(data)
}
